package com.example.car.adapter

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.car.R
import com.example.car.entity.ParkingEntity

class ParkingAdapter : BaseQuickAdapter<ParkingEntity,BaseViewHolder>(R.layout.item_parking) {
    override fun convert(holder: BaseViewHolder, item: ParkingEntity) {
        holder.getView<TextView>(R.id.tv_parking_number ).text =  "${item.spaceNumber}"
        holder.getView<TextView>(R.id.tv_occupied ).text =  "${item.spaceStatus}"
        holder.getView<TextView>(R.id.tv_area ).text =  "所属区域:${item.areaName}"
        holder.getView<TextView>(R.id.tv_type ).text =  "车位类型:${item.spaceType}"
        val type = holder.getView<TextView>(R.id.tv_occupied)
        if (item.spaceStatus .equals("已占用") ){
            type.setTextColor(android.graphics.Color.parseColor("#487DEE"))
            type.setBackgroundColor(android.graphics.Color.parseColor("#EFF6FF"))
            holder.getView<TextView>(R.id.tv_user ).text =  "使用人:${item.userName}"
            holder.getView<TextView>(R.id.tv_license ).text = "车牌号:${item.licensePlate}"
            holder.setGone(R.id.tv_user,false)
            holder.setGone(R.id.tv_license,false)
        }else if (item.spaceStatus .equals("空闲") ){
            type.setTextColor(android.graphics.Color.parseColor("#41B56B"))
            type.setBackgroundColor(android.graphics.Color.parseColor("#F0FDF4"))
            holder.getView<TextView>(R.id.tv_area)
            holder.setGone(R.id.tv_user,true)
            holder.setGone(R.id.tv_license,true)
        }else if (item.spaceStatus.equals("维护中")){
            type.setTextColor(android.graphics.Color.parseColor("#D19922"))
            type.setBackgroundColor(android.graphics.Color.parseColor("#FEFCE8"))
            holder.setGone(R.id.tv_license,true)
            holder.getView<TextView>(R.id.tv_user ).text =  "维护原因:${item.userName}"
            holder.setGone(R.id.tv_user,false)
        }else {
            type.setTextColor(android.graphics.Color.parseColor("#41B56B"))
            type.setBackgroundColor(android.graphics.Color.parseColor("#F0FDF4"))
            holder.getView<TextView>(R.id.tv_occupied ).text =  "空闲"
            holder.setGone(R.id.tv_user,true)
            holder.setGone(R.id.tv_license,true)
        }
    }
}